#ifndef __DEBUG__H
#define __DEBUG__H
#include "types.h"
#include "View.h"

// #define DEBUG_BREAK_IF_GOT_JUNCTION_AT_END_OF_MAIN_VEIN 1

// #define DEBUG_BREAK_AT_JUNCTION_AT_STATE 207

/** can be set to 0/undef, 2, or something else */
// #define DEBUG_STOP_AT_WALKUNTIL_END 2

#include <iostream>

class Debug {
public:
	static void Break() {
		__asm__ ("int $3");
		__asm__ ("nop");	
	}
	
	static void DumpDebugInfoAndBreak(View *v) {
		DumpDebugInfo(v);
		__asm__ ("int $3");
		__asm__ ("nop");
	}
	
	static void DumpDebugInfo(View *v) {
		static S32 nIndex = 10000;
		char szFileName[256];
		sprintf(szFileName, "debug%ld.pgm", ++nIndex);
		v->SaveAsImage(szFileName); /* debug dump */
		Rect<S32> boundingRect;
		v->GetBoundingRect(&boundingRect);
		S32 nCenterRow = -boundingRect.Top(), nCenterCol = -boundingRect.Left();
		std::cout << "Debug image dumped, filename is: " << szFileName << " center is at: " 
		          << nCenterRow << ", " << nCenterCol << std::endl;
		std::cout << "View center is: " << v->GetCenterRow() << ", " << v->GetCenterCol() 
				<< std::endl;	
	}
	
	static std::ostream & Stream() { return std::cerr; }
public:
	static bool g_bAtMainVein;
};

#endif
